package cn.cyl.user.controller;

import cn.cyl.basic.exception.BusinessException;
import cn.cyl.basic.util.AjaxResult;
import cn.cyl.basic.util.PageList;
import cn.cyl.user.domain.Logininfo;
import cn.cyl.user.dto.LoginDto;
import cn.cyl.user.query.LogininfoQuery;
import cn.cyl.user.service.LogininfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
* 后端接口类；
*/
@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    public LogininfoService logininfoService;

    @PostMapping("/account")
    public AjaxResult account(@RequestBody LoginDto dto){
       try {
           Map<String,Object> map=logininfoService.account(dto);
           AjaxResult ajaxResult = new AjaxResult();
           ajaxResult.setObj(map);
           return ajaxResult;
       } catch (BusinessException e) {
           return new AjaxResult(false,e.getMessage());
       }catch (Exception e) {
           e.printStackTrace();
           return new AjaxResult(false,"网络异常");
       }
   }


   //微信注册
    @PostMapping("/wechat")
    public AjaxResult wechatLogin(@RequestBody Map<String,String> map){
        try {
          AjaxResult ajaxResult = logininfoService.wechatLogin(map);
            System.out.println(ajaxResult.getObj());
            return ajaxResult;
        }catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"网络异常");
        }
    }

    //微信绑定
    @PostMapping("/wechat/binder")
    public AjaxResult wechatBinder(@RequestBody Map<String,String> map){
        try {
            return logininfoService.wechatBinder(map);
        }catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"网络异常");
        }
    }

}
